const Koa = require('koa')
const cors = require('koa-cors')
const koaBody = require('koa-body')
const koaStatic = require('koa-static')
const path = require('path')
const userRouter = require('./src/routers/user.js');
const { port } = require('./src/models/defaultConfig.js')
const app = new Koa()

//为应用使用中间件
// 静态文件中间件
app.use(koaStatic(path.join(__dirname,'./pubilc')))
// 请求体parse 中间件
app.use(koaBody({
    multipart:true,
    formidable:{
        maxFieldsSize:10 * 1024 * 1024, // 设置最大为10M
        uploadDir: path.resolve(__dirname, './public'),// 可以填一个路径
    }
}))
// 允许所有地方的请求
app.use(cors())

// 路由定义
app.use(userRouter)

app.listen(port , () => console.log(`app is listening at port ${port} `))


